<?php

namespace Modules\Asset\Exports;

use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithTitle;

use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;

// use PHPExcel_Cell_DataType;
use PhpOffice\PhpSpreadsheet\Cell\DataType;

use Modules\Order\Entities\Order;

class WithdrawExport implements WithColumnFormatting, FromCollection, WithTitle, WithHeadings, WithMapping, ShouldAutoSize
{
    use Exportable;

    private $list;

    public function __construct($list)
    {
        $this->list = $list;
    }

    public function columnFormats(): array
    {
        return [];
        // return [
        //     'O' => DataType::TYPE_STRING
        // ];
    }

    /**
     * @return Builder
     */
    public function collection()
    {
        return $this->list;
        // return BookInfo::where('booking_session_id', $this->session->id)->displayed();
    }

    /**
     * @return string
     */
    public function title(): string
    {
        return '记录导出';
    }

    public function map($item): array
    {
        $user = $item->user;

        $typeList =  [
          'alipay' => '支付宝(手动)',
          'wechat_pay' => '微信转帐(手动)',
          'wechat_pay_auto' => '微信零钱(自动)',
          'bank' => '银行卡(手动)',
          'bank_auto' => '银行卡(自动)'
        ];

        $res = [
            $item->id,
            $item->number,
            $user->name,
            $user->phone,
            $user->status === 1 ? '正常' : '已禁用',
            $item->value / 100,
            $typeList[$item->withdraw_type],
            $item->account_qrcode,
            $item->bank_name,
            $item->bank_account_name,
            $item->bank_account_number . "\t",
            $item->account,
            $item->created_at,
            $item->union_status_text,
        ];

        return $res;
    }

    public function headings(): array
    {
        return [
            '唯一ID',
            '编号',
            '用户名',
            '手机号',
            '用户状态',
            '提现金额',
            '提现类型',
            '收款码',
            '银行名称',
            '银行卡户名',
            '银行卡编号',
            '帐号备注',
            '提现时间',
            '提现状态',
        ];
    }
}
